<?php

class Tintuc_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    private $tbl = "tintuc";
    function get_all() {
        $this->db->select("tin.tieude, tin.noi dung, tin.thoigian, tt.ten, tt.anh,pl.ten");
        $this->db->from($this->tbl." as tin");
        $this->db->join("trungtam as tt", $this->tbl.".idTT = tt.id");
        $this->db->join("loaitrungtam as pl", "tt.id_phanloai = pl.id");
        
        return  $this->db->get();
    }
    function get_by_loaiTT($id_loaiTT) {
        $this->db->select("tin.tieude, tin.noi dung, tin.thoigian, tt.ten, tt.anh,pl.ten");
        $this->db->from($this->tbl." as tin");
        $this->db->join("trungtam as tt", $this->tbl.".idTT = tt.id");
        $this->db->join("loaitrungtam as pl", "tt.id_phanloai = pl.id");
        $this->db->where("pl.id",$id_loaiTT);
        
        return  $this->db->get();
    }
    function get_by_id($id) {
        $this->db->select("tin.tieude, tin.noi dung, tin.thoigian, tt.ten, tt.anh,pl.ten");
        $this->db->from($this->tbl." as tin");
        $this->db->join("trungtam as tt", $this->tbl.".idTT = tt.id");
        $this->db->join("loaitrungtam as pl", "tt.id_phanloai = pl.id");
        $this->db->where('tin.id',$id);
        $this->db->limit(1);
        
        return  $this->db->get();
    }
}

